package com.cheetah.session;

import com.cheetah.constants.KeyConstants;
import com.cheetah.support.redis.RedisClient;
import com.cheetah.support.redis.enums.RedisDBEnum;
import com.cheetah.support.redis.RedisTemplateProcessor;
import com.cheetah.utils.KeyUtil;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author Administrator
 * @Date 2019/9/7
 * @Version V1.0
 * @Description: 用户session 管理类
 **/
@Component
public class SessionManager {

    @Autowired
    @Qualifier("REDIS_IM")
    private RedisClient redisClient;

    public static ConcurrentHashMap<String,Channel> channels = new ConcurrentHashMap<>();

    public void login(String userId,Channel channel){
        channels.put(channel.id().asLongText(),channel);
        redisClient
                .sAdd(KeyUtil.generate(KeyConstants.USER_CHANNELS_S, userId),
                        channel.id().asLongText());
    }
}
